<template>
  <!-- tab切换-->
  <div class="box">
    <div class="menu">
      <ul>
        <li
          v-for="(item, index) in titles"
          @click="show = index"
          :class="{ active: index === show, tab: true }"
        >
          {{ item.title }}
        </li>
      </ul>
    </div>
    <div class="content">
      <div
        v-for="(item, index) in contents"
        :class="{ selected: index === show, main: true }"
      >
        {{ item.content }}
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from "vue";
// tab切换:
let titles = ref([
  { id: 1, title: "html" },
  { id: 2, title: "js" },
  { id: 3, title: "vue" },
]);
let contents = ref([
  { id: 1, content: "html练习1111" },
  { id: 2, content: "js练习2222" },
  { id: 3, content: "vue练习3333" },
]);
// 记录单击内容的下标
const show = ref(0);
</script>


<style scoped>
* {
  padding: 0;
  margin: 0;
}
.box {
  width: 600px;
  height: 300px;
  border: 1px solid skyblue;
  margin: 50px auto;
}

.menu .tab {
  list-style-type: none;
  float: left;
  cursor: pointer;
  width: 200px;
  line-height: 50px;
  text-align: center;
  border: 1px solid #87ceeb;
  box-sizing: border-box;
}

.content .main {
  padding: 20px;
  display: none;
  text-indent: 20px;
  word-wrap: break-word;
}

.content .selected {
  display: block;
}

.active {
  background-color: pink;
}
</style>